home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / stdlib / RCS / atol.c,v < prev    next >
Encoding:
Text File  |  1991-12-03  |  2.6 KB  |  145 lines

  1. head     1.2;
  2. branch   ;
  3. access   ;
  4. symbols  sprited:1.2.1;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.2
  10. date     89.03.22.00.47.01;  author rab;  state Exp;
  11. branches 1.2.1.1;
  12. next     1.1;
  13.  
  14. 1.1
  15. date     88.04.28.17.20.25;  author ouster;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19. 1.2.1.1
  20. date     91.12.02.21.57.52;  author kupfer;  state Exp;
  21. branches ;
  22. next     ;
  23.  
  24.  
  25. desc
  26. @@
  27.  
  28.  
  29. 1.2
  30. log
  31. @*** empty log message ***
  32. @
  33. text
  34. @/* 
  35.  * atol.c --
  36.  *
  37.  *    Source code for the "atol" library procedure.
  38.  *
  39.  * Copyright 1988 Regents of the University of California
  40.  * Permission to use, copy, modify, and distribute this
  41.  * software and its documentation for any purpose and without
  42.  * fee is hereby granted, provided that the above copyright
  43.  * notice appear in all copies.  The University of California
  44.  * makes no representations about the suitability of this
  45.  * software for any purpose.  It is provided "as is" without
  46.  * express or implied warranty.
  47.  */
  48.  
  49. #ifndef lint
  50. static char rcsid[] = "$Header: /sprite/src/lib/c/stdlib/RCS/atol.c,v 1.1 88/04/28 17:20:25 ouster Exp Locker: rab $ SPRITE (Berkeley)";
  51. #endif /* not lint */
  52.  
  53. #include <stdlib.h>
  54. #include <ctype.h>
  55.  
  56. /*
  57.  *----------------------------------------------------------------------
  58.  *
  59.  * atol --
  60.  *
  61.  *    Convert an ASCII string into a long integer.
  62.  *
  63.  * Results:
  64.  *    The return value is the integer equivalent of string.  If there
  65.  *    are no decimal digits in string, then 0 is returned.
  66.  *
  67.  * Side effects:
  68.  *    None.
  69.  *
  70.  *----------------------------------------------------------------------
  71.  */
  72.  
  73. long int
  74. atol(string)
  75.     register char *string;    /* String of ASCII digits, possibly
  76.                  * preceded by white space.  For bases
  77.                  * greater than 10, either lower- or
  78.                  * upper-case digits may be used.
  79.                  */
  80. {
  81.     register long int result = 0;
  82.     register unsigned int digit;
  83.     int sign;
  84.  
  85.     /*
  86.      * Skip any leading blanks.
  87.      */
  88.  
  89.     while (isspace(*string)) {
  90.     string += 1;
  91.     }
  92.  
  93.     /*
  94.      * Check for a sign.
  95.      */
  96.  
  97.     if (*string == '-') {
  98.     sign = 1;
  99.     string += 1;
  100.     } else {
  101.     sign = 0;
  102.     if (*string == '+') {
  103.         string += 1;
  104.     }
  105.     }
  106.  
  107.     for ( ; ; string += 1) {
  108.     digit = *string - '0';
  109.     if (digit > 9) {
  110.         break;
  111.     }
  112.     result = (10*result) + digit;
  113.     }
  114.  
  115.     if (sign) {
  116.     return -result;
  117.     }
  118.     return result;
  119. }
  120. @
  121.  
  122.  
  123. 1.2.1.1
  124. log
  125. @Initial branch for Sprite server.
  126. @
  127. text
  128. @d17 1
  129. a17 1
  130. static char rcsid[] = "$Header: /sprite/src/lib/c/stdlib/RCS/atol.c,v 1.2 89/03/22 00:47:01 rab Exp $ SPRITE (Berkeley)";
  131. @
  132.  
  133.  
  134. 1.1
  135. log
  136. @Initial revision
  137. @
  138. text
  139. @d17 2
  140. a18 2
  141. static char rcsid[] = "$Header: proto.c,v 1.2 88/03/11 08:39:08 ouster Exp $ SPRITE (Berkeley)";
  142. #endif not lint
  143. d20 1
  144. @
  145.